//
//  FeedbackViewController.m
//  nmrsc
//
//  Created by xumckay on 16/1/15.
//  Copyright © 2016年 bric. All rights reserved.
//

#import "FeedbackViewController.h"
#import "functionBtn.h"
@interface FeedbackViewController ()

@property (strong,nonatomic)UILabel *showLabel;
@property (strong,nonatomic)UITextView *textView;
@property (strong,nonatomic)UITextField *numberTextField;
@property (strong,nonatomic)UILabel *calculateLabel;
@property (strong,nonatomic)UIButton *tijiao;

@end

@implementation FeedbackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NAVBAR(@"意见反馈");
    
    self.view.backgroundColor=[UIColor whiteColor];
    UIButton *backBtn=[[UIButton alloc]initWithFrame:CGRectMake(0,0,8.5,15)];
    [backBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backClicked) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:backBtn];
    
    [self makeView];
    
    _tijiao=[[UIButton alloc]initWithFrame:CGRectMake(0,0,30,15)];
    [_tijiao setTitle:@"提交" forState:UIControlStateNormal];
    _tijiao.titleLabel.font=[UIFont systemFontOfSize:14];
    [_tijiao setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [_tijiao addTarget:self action:@selector(tijiaoBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    _tijiao.enabled=NO;
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:_tijiao];
}

-(void)makeView
{
    UIView *functionView=[[UIView alloc]initWithFrame:CGRectMake(0,64,kDeviceWidth,45)];
    UILabel *tiplabel=[[UILabel alloc]initWithFrame:CGRectMake(15,0,150,45)];
    tiplabel.text=@"反馈类型";
    tiplabel.textAlignment=NSTextAlignmentLeft;
    tiplabel.font=[UIFont systemFontOfSize:15];
    tiplabel.textColor=[UIColor blackColor];
    [functionView  addSubview:tiplabel];
    
    UIView *sep=[[UIView alloc]initWithFrame:CGRectMake(0,44.5,kDeviceWidth,0.5)];
    sep.backgroundColor=COLOR(200, 200, 200, 1);
    [functionView addSubview:sep];
    
    functionBtn *funcBtn=[[functionBtn alloc]initWithFrame:CGRectMake(kDeviceWidth/2,0,kDeviceWidth/2,45)];
    [funcBtn setTitle:@"功能" forState:UIControlStateNormal];
    [funcBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    funcBtn.titleLabel.textAlignment=NSTextAlignmentRight;
    funcBtn.titleLabel.font=[UIFont systemFontOfSize:15];
    [funcBtn setImage:[UIImage imageNamed:@"right-2"] forState:UIControlStateNormal];
    [functionView addSubview:funcBtn];
    [self.view addSubview:functionView];
    
    UIView *sep2=[[UIView alloc]initWithFrame:CGRectMake(0,45+64,kDeviceWidth,15)];
    sep2.backgroundColor=COLOR(250, 250, 250, 1);
    [self.view addSubview:sep2];
    
    UIView *sep3=[[UIView alloc]initWithFrame:CGRectMake(0,64+45+14.5,kDeviceWidth,0.5)];
    sep3.backgroundColor=COLOR(200, 200, 200, 1);
    [self.view addSubview:sep3];
    
    _textView=[[UITextView alloc]initWithFrame:CGRectMake(15,64+45+15+5,kDeviceWidth-30,150)];
    _textView.backgroundColor=[UIColor whiteColor];
    _textView.font=[UIFont systemFontOfSize:14];
    _textView.delegate=self;
    _textView.returnKeyType=UIReturnKeyDone;
    [_textView becomeFirstResponder];
    [self.view addSubview:_textView];
    
    _showLabel=[[UILabel alloc]initWithFrame:CGRectMake(20,64+45+15+15,kDeviceWidth-30,14)];
    _showLabel.font=[UIFont systemFontOfSize:14];
    _showLabel.text=@"请输入产品意见，我们将不断优化体验";
    _showLabel.textColor=COLOR(215, 215, 215, 1);
    [self.view addSubview:_showLabel];
    
    UIView *sep4=[[UIView alloc]initWithFrame:CGRectMake(0,_textView.y+_textView.height-0.5,kDeviceWidth,0.5)];
    sep4.backgroundColor=COLOR(200, 200, 200, 1);
    [self.view addSubview:sep4];
    
    UIView *sep5=[[UIView alloc]initWithFrame:CGRectMake(0,sep4.y+0.5,kDeviceWidth,kDeviceHeight-sep4.y-0.5)];
    sep5.backgroundColor=COLOR(250, 250, 250, 1);
    [self.view addSubview:sep5];
    
    UIView *whiteBackView=[[UIView alloc]initWithFrame:CGRectMake(0,sep4.y+0.5+15,kDeviceWidth,45)];
    whiteBackView.backgroundColor=[UIColor whiteColor];
    
    [self.view addSubview:whiteBackView];
    
    _numberTextField=[[UITextField alloc]initWithFrame:CGRectMake(15,0,kDeviceWidth-30,45)];
    _numberTextField.placeholder=@"请输入您的手机号/邮箱";
    _numberTextField.backgroundColor=[UIColor whiteColor];
    _numberTextField.keyboardType=UIKeyboardTypeEmailAddress;
    _numberTextField.returnKeyType=UIReturnKeyDone;
    _numberTextField.delegate=self;
    [whiteBackView addSubview:_numberTextField];
    
    _calculateLabel=[[UILabel alloc]initWithFrame:CGRectMake(kDeviceWidth-30-100,150-20,100,15)];
    _calculateLabel.text=@"0/100";
    _calculateLabel.font=[UIFont systemFontOfSize:14];
    _calculateLabel.textAlignment=NSTextAlignmentRight;
    _calculateLabel.textColor=COLOR(215, 215, 215, 1);
    [_textView addSubview:_calculateLabel];
    
    UIView *sep6=[[UIView alloc]initWithFrame:CGRectMake(0,64+45+15+150+14.5+5,kDeviceWidth,0.5)];
    sep6.backgroundColor=COLOR(200, 200, 200, 1);
    [self.view addSubview:sep6];
    
    UIView *sep7=[[UIView alloc]initWithFrame:CGRectMake(0,64+45+15+150+15+44.5+5,kDeviceWidth,0.5)];
    sep7.backgroundColor=COLOR(200, 200, 200, 1);
    [self.view addSubview:sep7];
    
}

#pragma mark   --UITextViewDelegate

-(void)textViewDidChange:(UITextView *)textView
{
    if (textView.text.length>0) {
        _showLabel.text=@"";
        [_tijiao setTitleColor:COLOR(36, 148, 88, 1) forState:UIControlStateNormal];
        _tijiao.enabled=YES;
    }
    else
    {
        _showLabel.text=@"请输入产品意见，我们将不断优化体验";
        [_tijiao setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        _tijiao.enabled=NO;
    }
}

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"]) {
        [_textView resignFirstResponder];
        return NO;
    }
    
    NSString *temp=[textView.text stringByReplacingCharactersInRange:range withString:text];
    NSInteger remainTextNum=100;
    
    if (range.location>100) {
        remainTextNum = 0;
        [[HLManager sharedManager]showHudText:@"请输入小于100个字！" detailsText:nil afterDelay:1];
        return YES;
    }
    else
    {
        NSInteger existTextNum = [temp length];
        remainTextNum =100-existTextNum;
        _calculateLabel.text = [NSString stringWithFormat:@"%ld/100",(long)remainTextNum];
        
        return YES;
    }
    
    
    
    return YES;
}


#pragma mark   --UITextFieldDelegate

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.view endEditing:YES];
    return YES;
}



-(void)backClicked
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)tijiaoBtnClicked
{
    if (_textView.text.length>100) {
        [[HLManager sharedManager]showHudText:@"字数超过100了" detailsText:nil afterDelay:1];
    }
    else
    {
        
        
        
        
    }
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


@end
